---
title: "Table 1"
output: pdf_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(knitr)
library(survey)
library(foreign)
library(car)
library(xtable)
mil_conf.df <- read.csv("~/Dropbox/Public_Conf_Mil/Data_and_code/mil_conf.csv")
```

```{r echo = FALSE}
source("~/Dropbox/Public_Conf_Mil/Data_and_code/PCM_cleaning.R")

milconf_design <-
  svydesign(
    id = ~ 1,
    weights = ~ weight,
    data = mil_conf.df
  )
```

```{r echo = FALSE}
tab1 <- matrix(NA, nrow = 3, ncol = 4)
rownames(tab1) <- c("Military", "Military Leaders", "Retired Generals and Admirals")
colnames(tab1) <- c("Democrats", "Independents", "Republicans", "Overall")
tab1[1,1] <- (svyby(~Q8_fac, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q8_fac, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[1,2] <- (svyby(~Q8_fac, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q8_fac, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[1,3] <- (svyby(~Q8_fac, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q8_fac, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[1,4] <- (svyby(~Q8_fac, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,2] + svyby(~Q8_fac, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,3]) * 100
tab1[2,1] <- (svyby(~Q10_fac, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q10_fac, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[2,2] <- (svyby(~Q10_fac, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q10_fac, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[2,3] <- (svyby(~Q10_fac, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q10_fac, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[2,4] <- (svyby(~Q10_fac, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,2] + svyby(~Q10_fac, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,3]) * 100
tab1[3,1] <- (svyby(~Q11_fac, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q11_fac, ~DOV_ASSIGNMENT_A+dem, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[3,2] <- (svyby(~Q11_fac, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q11_fac, ~DOV_ASSIGNMENT_A+ind, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[3,3] <- (svyby(~Q11_fac, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,3] + svyby(~Q11_fac, ~DOV_ASSIGNMENT_A+rep, milconf_design, svymean, na.rm = TRUE)[9,4]) * 100
tab1[3,4] <- (svyby(~Q11_fac, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,2] + svyby(~Q11_fac, ~DOV_ASSIGNMENT_A, milconf_design, svymean, na.rm = TRUE)[1,3]) * 100
tab1_xt <- xtable(tab1)
digits(tab1_xt) <- 0
align(tab1_xt) <- "rcccc"
```

```{r echo = FALSE, results = "asis"}
print(tab1_xt, comment = FALSE, caption.placement = "top", size="\\large")
```
